public class TestTypeAutoConvert {
    public static void main(String[] args) {
        int a = 2345;
        long b = a;
       // int c = b; 从容量小，范围小的类型可以自动转换为容量大的类型
        //long类型不能自动转为int
        float c = b;
        double d = b;
        System.out.println(c);
        System.out.println(d);

        //整形常量int 可以赋值给byte short char 类型变量，但不能超出范围
        short e = 123;
        byte f = 127;
        //byte f2 = 128;//超出范围 -128 ~ 127
        char h = 25000;
        System.out.println(h);

        //强制转换    溢出或丢失精度
        double aa = 3.1415;
        int bb =(int)aa;//丢失精度  浮点数强制转成整数，直接丢失小数部分（不会四舍五入）
        System.out.println(bb);  //3

        int cc = 97;
        System.out.println((char)cc);  //a

        //强制转换，超出表述范围，则会转成一个完全不同的值
        byte dd = (byte)200;
        System.out.println(dd);  //-56

        /*int money = 1000000000;//10亿
        int year  = 20;
        int total = money*year;
        System.out.println(total);*/

        int money = 1000000000;
        int year = 20;
        long total1 = money*year; //错误 右边计算出溢出的int
        int total2 = money*year; //错误   溢出的int赋值给int
        long total3 = 1L*money*year; //正确
        long total = money*(long)year;  //正确 运算中有long则会转成long
        System.out.println(total1);
        System.out.println(total2);
        System.out.println(total3);
        System.out.println(total);

        //long num = 100*60*24*365*80;//溢出
        long num = 100L*60*24*365*80;
        System.out.println(num);
    }
}
